package com.lmx.persistence.service;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.lmx.common.constants.CommonConstants;
import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.tmodel.CustomerServiceItem;
import com.lmx.repoDomain.tmodel.Tenant;

/**
 *
 * @author ytche
 * @date 2017年9月9日
 *
 */
@Service
public class CustomerServiceItemServiceImpl extends BaseCrudServiceImpl<CustomerServiceItem>
		implements CustomerServiceItemService {

	@SuppressWarnings("unchecked")
	@Override
	public void createDefault(Tenant tenant) {
		String queryStr = "From CustomerServiceItem as srv where srv.tenant is null and code=:code";
		List<CustomerServiceItem> services = super.em.createQuery(queryStr)
				.setParameter("code", CommonConstants.CUSTOMER_SERVICE_ITEM_CODE_OTHER)
				.getResultList();
		CustomerServiceItem newServiceItem = new CustomerServiceItem();
		BeanUtils.copyProperties(services.get(0), newServiceItem);
		newServiceItem.setTenant(tenant);
		super.save(newServiceItem);
	}
}
